﻿using System;

namespace DataCenter.Models
{
    public abstract class Symbol
    {
        public abstract string symbol { get; protected set; }
    }

    public interface NameAndTrade
    {
        string name { get; set; }
        float trade { get; set; }
    }

    public interface IInfo
    {
        string symbol { get; }
        string name { get; }
        string code { get; }
    }
    
    //涨跌榜
    public class ZDB:Symbol,NameAndTrade
    {
        public override string symbol { get; protected set; }
        public string name { get; set; }
        public float changepercent { get; private set; }
        public float trade { get; set; }
    }

    //换手率，大单频现的模型也是这个
    public class HSTop:Symbol,NameAndTrade
    {
        public override string symbol { get; protected set; }
        public string name { get; set; }
        public float turnover { get; private set; }
        public float trade { get; set; }
        public float changepercent { get; private set; }
    }

    public class CJETop:Symbol,NameAndTrade
    {
        public override string symbol { get; protected set; }
        public string name { get; set; }
        public float amount { get; private set; }
        public float trade { get; set; }
        public float changepercent { get; private set; }
    }

    public class ZLLR:Symbol,NameAndTrade
    {
        public override string symbol { get; protected set; }
        public string name { get; set; }
        public float zllr { get; private set; }
        public float zllc { get; private set; }
        public float jlr { get; private set; }
        public float trade { get; set; }
        public float changepercent { get; private set; }
    }

    public class zhishuYL:IInfo
    {
        public string symbol { get; private set; }
        public string code
        {
            get
            {
                if (symbol.Length >= 8)
                    return symbol.Substring(2, 6);
                return symbol;
            }
        }
        public string name { get; private set; }
        public float trade { get; private set; }
        public float open { get; private set; }
        public float high { get; private set; }
        public float low { get; private set; }
        public float change { get; private set; }
        public float changepercent { get; private set; }
        public float amplitude { get; private set; }
        public int vol { get; private set; }
        public float amount { get; private set; }
        public float qrr { get; private set; }
        public int upnum { get; private set; }
        public int flatnum { get; private set; }
        public int downnum { get; private set; }
    }

    public class Kline
    {
        public float open { get; private set; }
        public float close { get; private set; }
        public float high { get; private set; }
        public float low { get; private set; }
        public float bodyHigh { get; set; }
        public float bodyLow { get; set; }
        public float ma5 { get; set; }
        public float ma10 { get; set; }
        public float ma20 { get; set; }
        public float ma30 { get; set; }
        public float vol { get; private set; }
        public DateTime time { get; private set; }
        //private static string indexName = "time";

        public override string ToString()
        {
            return string.Format("开盘价：{0}，收盘价：{1}，最高价：{2}，最低价：{3}，成交量：{4}，时间：{5}", open, close, high, low, vol, time);
        }
    }

    public class Tick
    {
        public float trade { get; private set; }
        public float average { get; set; }
        public float vol { get; set; }
        public DateTime time { get; private set; }
        static string indexName = "time";

        public override string ToString()
        {
            return "价格" + trade.ToString() + ", 成交量" + vol.ToString() + ", 时间" + time.ToString();
        }
    }

    public class StockInfo:IInfo
    {
        public string symbol { get; private set; }
        public string code
        {
            get
            {
                if (symbol.Length >= 8)
                    return symbol.Substring(2, 6);
                return symbol;
            }
        }
        public string name { get; private set; }
        public float trade { get; private set; }
        public float change { get; private set; }
        public float changepercent { get; private set; }

        //盘口
        public float open { get; private set; }
        public float preclose { get; private set; }
        public float average { get; private set; }
        public float zt { get; private set; }
        public float dt { get; private set; }
        public float qrr { get; private set; }//量比 quantity relative ratio
        public float cmt
        {
            get
            {
                float totalBuy = buy1vol + buy2vol + buy3vol + buy4vol + buy5vol;
                float totalSell = sell1vol + sell2vol + sell3vol + sell4vol + sell5vol;
                return (totalBuy - totalSell) / (totalBuy + totalSell);
            }
        }//委比 The Committee
        public float turnover { get; private set; }//换手率
        public float high { get; private set; }
        public float low { get; private set; }
        public float amplitude { get; private set; }//振幅
        public int vol { get; private set; }
        public float amount { get; private set; }
        public int outvol { get; private set; }
        public int invol { get; private set; }
        public float circulatingShares
        {
            get
            {
                var r = circulatingAmount / trade;
                if (float.IsNaN(r) || float.IsInfinity(r))
                    return 0;
                return r;
            }
        }//流通股(亿)
        public float circulatingAmount { get; private set; }//流通值
        public float totalShares
        {
            get
            {
                var r = totalAmount / trade;
                if (float.IsNaN(r) || float.IsInfinity(r))
                    return 0;
                return r;
            }
        }//总股本(亿)
        public float totalAmount { get; private set; }//总市值
        public float pe { get; private set; }//动态市盈率
        public float spe { get; private set; }//静态市盈率 static pe
        public float ttm { get; private set; }//市盈率（TTM）
        public float pb { get; private set; }//市净率

        //买卖
        public float buy1 { get; private set; }
        public int buy1vol { get; private set; }
        public float buy2 { get; private set; }
        public int buy2vol { get; private set; }
        public float buy3 { get; private set; }
        public int buy3vol { get; private set; }
        public float buy4 { get; private set; }
        public int buy4vol { get; private set; }
        public float buy5 { get; private set; }
        public int buy5vol { get; private set; }
        public float sell1 { get; private set; }
        public int sell1vol { get; private set; }
        public float sell2 { get; private set; }
        public int sell2vol { get; private set; }
        public float sell3 { get; private set; }
        public int sell3vol { get; private set; }
        public float sell4 { get; private set; }
        public int sell4vol { get; private set; }
        public float sell5 { get; private set; }
        public int sell5vol { get; private set; }

        private static string indexName = "symbol";
    }

    /// <summary>
    /// 五档买卖
    /// </summary>
    public class BS5
    {
        public float buy1 { get; private set; }
        public int buy1vol { get; private set; }
        public float buy2 { get; private set; }
        public int buy2vol { get; private set; }
        public float buy3 { get; private set; }
        public int buy3vol { get; private set; }
        public float buy4 { get; private set; }
        public int buy4vol { get; private set; }
        public float buy5 { get; private set; }
        public int buy5vol { get; private set; }

        public float sell1 { get; private set; }
        public int sell1vol { get; private set; }
        public float sell2 { get; private set; }
        public int sell2vol { get; private set; }
        public float sell3 { get; private set; }
        public int sell3vol { get; private set; }
        public float sell4 { get; private set; }
        public int sell4vol { get; private set; }
        public float sell5 { get; private set; }
        public int sell5vol { get; private set; }
    }

    /// <summary>
    /// 盘口
    /// </summary>
    public class Handicap
    {
        public float open { get; private set; }
        public float preclose { get; private set; }
        public float average { get; private set; }
        public float zt { get; private set; }
        public float dt { get; private set; }
        public float qrr { get; private set; }//量比 quantity relative ratio
        public float cmt { get; private set; }//委比 The Committee
        public float turnover { get; private set; }//换手率
        public float high { get; private set; }
        public float low { get; private set; }
        public float amplitude { get; private set; }//振幅
        public int vol { get; private set; }
        public float amount { get; private set; }
        public int outvol { get; private set; }
        public int invol { get; private set; }
        public float circulatingShares { get; private set; }//流通股
        public float circulatingAmount { get; private set; }//流通值
        public float totalShares { get; private set; }//总股本
        public float totalAmount { get; private set; }//总市值
        public float pe { get; private set; }//动态市盈率
        public float spe { get; private set; }//静态市盈率 static pe
        public float ttm { get; private set; }//市盈率（TTM）
        public float pb { get; private set; }//市净率
    }

    public class BKRanking
    {
        public string symbol { get; private set; }
        public string name { get; private set; }
        public int companyNum { get; private set; }
        public float averagePrice { get; private set; }
        public float change { get; private set; }
        public float changepercent { get; private set; }
        public float vol
        {
            get { return _vol / 100; }
            private set { _vol = value; }
        }
        public float amount { get; private set; }
        public string top1name { get; private set; }
        public float top1changepercent { get; private set; }
        public float top1trade { get; private set; }
        public float top1change { get; private set; }
        public string top1symbol { get; private set; }
        public string top1code
        {
            get
            {
                if (top1symbol!=null&& top1symbol.Length >= 8)
                    return top1symbol.Substring(2, 6);
                return "";
            }
        }

        private float _vol;
    }

    public class SearchItem
    {
        public string market{ get; private set; }
        public string code { get; private set; }
        public string name { get; private set; }
        public string pinyin { get; private set; }
        public string type { get; private set; }
        public string symbol { get { return market + code; } }
    }

    public class User
    {
        public string userId { get; private set; }
        public string nickname { get; private set; }
        public int status { get; private set; }

        public User(string userId, string nickname, int status)
        {
            this.userId = userId;
            this.nickname = nickname;
            this.status = status;
        }
    }
}
